// pages/category/category.js
const db = wx.cloud.database()
Page({
  data: {
    currentIndex:0,
    currentIndexMenu:"手机",
    categoryMenu:[],
    currentMuneItem:[]
  },
  onLoad: function (options) {
    let that = this;
    // 拿取左边菜单
    db.collection('category-left').get({
      success:function(res){
        that.setData({
          categoryMenu:res.data
        })
      }
    }),
    // 拿取右边菜单
    db.collection('product').where({
      category:that.data.currentIndexMenu
    }).get({
      success:function(res){
        that.setData({
          currentMuneItem:res.data
        })
      }
    })
  },
  muneClick(event){
    let that = this
    this.setData({
      currentIndex:event.target.dataset.index,
      currentIndexMenu:event.target.dataset.name
    }),
    db.collection('product').where({
      category:that.data.currentIndexMenu
    }).get({
      success:function(res){
        that.setData({
          currentMuneItem:res.data
        })
      }
    })
  }
})